<template>
  <div class="init_main">
    <p class="name_sty">{{ name }}</p>
    <div class="query">
      <!-- 科室：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="test" value="test"> </el-option>
      </el-select> -->
      <el-button
        plain
        size="mini"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="getList"
        >查询</el-button
      >
      <!-- <el-button
        plain
        size="mini"
        icon="el-icon-plus"
        type="primary"
        @click="open_dialog('新增')"
        >新增</el-button
      > -->
      <el-button
        plain
        size="mini"
        icon="el-icon-edit"
        type="primary"
        @click="open_dialog('修改')"
        >回复</el-button
      >
      <!-- <el-button
        plain
        size="mini"
        icon="el-icon-delete"
        type="danger"
        @click="del_row"
        >删除</el-button
      > -->
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        height="600"
        highlight-current-row
        @current-change="row_click"
      >
        <el-table-column prop="Name" label="患者姓名" align="center">
        </el-table-column>
        <el-table-column prop="Score" label="评分" align="center">
        </el-table-column>
        <el-table-column
          prop="Comment"
          label="评价内容"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="CommentTime"
          label="评价时间"
          align="center"
        ></el-table-column>
        <el-table-column prop="Reply" label="回复标识" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.Reply" style="color: green">已回复</span>
            <span v-else style="color: red">未回复</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange_page"
        :current-page="query.CurrentPage"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
      >
      </el-pagination>
    </div> -->
    <!-- 弹层 -->
    <el-dialog
      :title="dialog_title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <div>患者评分：{{ form.Score }} (满分5分)</div>
      <div>评价内容：{{ form.Comment }}</div>
      <div>评价时间：{{ form.CommentTime }}</div>
      <div>
        我的回复：
        <el-input v-model="form.Reply" type="textarea" :rows="4" />
      </div>
      <div style="text-align: right">回复时间：{{ form.ReplyTime | time }}</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">关 闭</el-button>
        <el-button type="primary" @click="btn_ok" size="mini">确 认</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      query: {
        CurrentPage: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
      dialogVisible: false,
      dialog_title: "",
      row_info: {},
      form: {
        Type: "",
        Title: "",
        Content: "",
        Image: "",
      },
    };
  },
  filters: {
    time(time) {
      let oldDate = new Date(time);
      let newDate = new Date();
      var dayNum = "";
      var getTime = (newDate.getTime() - oldDate.getTime()) / 1000;

      if (getTime < 60 * 5) {
        dayNum = "刚刚";
      } else if (getTime >= 60 * 5 && getTime < 60 * 60) {
        dayNum = parseInt(getTime / 60) + "分钟前";
      } else if (getTime >= 3600 && getTime < 3600 * 24) {
        dayNum = parseInt(getTime / 3600) + "小时前";
      } else if (getTime >= 3600 * 24 && getTime < 3600 * 24 * 30) {
        dayNum = parseInt(getTime / 3600 / 24) + "天前";
      } else if (getTime >= 3600 * 24 * 30 && getTime < 3600 * 24 * 30 * 12) {
        dayNum = parseInt(getTime / 3600 / 24 / 30) + "个月前";
      } else if (time >= 3600 * 24 * 30 * 12) {
        dayNum = parseInt(getTime / 3600 / 24 / 30 / 12) + "年前";
      }

      let year = oldDate.getFullYear();
      let month = oldDate.getMonth() + 1;
      let day = oldDate.getDate();
      let hour = oldDate.getHours();
      let minute = oldDate.getMinutes();
      let second = oldDate.getSeconds();
      // return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + dayNum;
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
  },
  mounted() {
    this.name = this.$route.meta.title;
    this.getList();
  },
  methods: {
    getList() {
      this.$post(
        "https://mini.mdxrmyy.top:8881/api/Order/GetAll",
        this.query
      ).then((res) => {
        this.tableData = res.Data;
      });
    },
    open_windo(url) {
      window.open(url);
    },
    row_click(row) {
      if (!row) {
        this.row_info = {};
        return;
      }
      this.row_info = row;
    },
    del_row() {
      this.$get("/Option/SoftDelete/" + this.row_info.Id).then((res) => {
        this.getList();
      });
    },
    handleClose() {
      this.row_info = {};
      this.dialogVisible = false;
    },
    btn_ok() {
      // this.form
      var url = this.form.Id
        ? "https://mini.mdxrmyy.top:8881/api/Order/Update"
        : "https://mini.mdxrmyy.top:8881/api/Order/Update";
      this.form.ReplyTime = this.time(this.form.ReplyTime);
      if (this.form.Id) {
        this.$put(url, this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      } else {
        this.$post(url, this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      }
    },
    open_dialog(val) {
      //   this.dialog_title = val + "质控人员";
      //   if (val == "新增") {
      //     this.dialogVisible = true;
      //     return;
      //   }
      this.row_info.ReplyTime = new Date();
      if (val == "修改" && this.row_info) {
        this.form = this.row_info;
        this.dialogVisible = true;
        return;
        // this.$get("/Option/GetOneNew/" + this.row_info.Id).then((res) => {
        //   this.form = res.Data;
        //   this.dialogVisible = true;
        //   return;
        // });
      } else {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据后操作！",
        });
        return;
      }
    },
    time(time) {
      let oldDate = new Date(time);
      let newDate = new Date();
      var dayNum = "";
      var getTime = (newDate.getTime() - oldDate.getTime()) / 1000;

      if (getTime < 60 * 5) {
        dayNum = "刚刚";
      } else if (getTime >= 60 * 5 && getTime < 60 * 60) {
        dayNum = parseInt(getTime / 60) + "分钟前";
      } else if (getTime >= 3600 && getTime < 3600 * 24) {
        dayNum = parseInt(getTime / 3600) + "小时前";
      } else if (getTime >= 3600 * 24 && getTime < 3600 * 24 * 30) {
        dayNum = parseInt(getTime / 3600 / 24) + "天前";
      } else if (getTime >= 3600 * 24 * 30 && getTime < 3600 * 24 * 30 * 12) {
        dayNum = parseInt(getTime / 3600 / 24 / 30) + "个月前";
      } else if (time >= 3600 * 24 * 30 * 12) {
        dayNum = parseInt(getTime / 3600 / 24 / 30 / 12) + "年前";
      }

      let year = oldDate.getFullYear();
      let month = oldDate.getMonth() + 1;
      let day = oldDate.getDate();
      let hour = oldDate.getHours();
      let minute = oldDate.getMinutes();
      let second = oldDate.getSeconds();
      // return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + dayNum;
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
  },
};
</script>

<style scoped lang='scss'>
.init_main {
  background-color: #fff;
  height: calc(100vh - 60px);
  border: 1px solid #333;
  border-radius: 5px;
  margin: 5px;
  padding: 10px;
  font-family: "FangSong";
  color: #000;
  .name_sty {
    color: #000;
    font-weight: 700;
    font-size: 18px;
    font-family: "FangSong";
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
  }
  .table {
    margin-top: 15px;
  }
  .page {
    text-align: right;
  }
}
::v-deep .el-table__body tr.current-row > td.el-table__cell {
  background-color: rgb(208, 229, 250);
  color: rgb(65, 158, 255);
  font-weight: 700;
}
.tac {
  text-align: center;
}
</style>